<?PHP
if (!session_start()) { session_start(); };
/*if (!isset($_SESSION['lgnapproved'])) {
	die(header('Location: login.php'));
}*/

include("functions.php");
include("cnnxn.php");
connect();

if (isset($_POST['submit'])) {
	
	$dateadded=date("Y-m-d");
	
	$fieldnames="";
	$tempvalue="";
	$modstring="";
	while (list($key,$value) = each($_POST)) {
	if ($value!='modify') {
		if (ctype_digit($value)) {
		   $tempvalue=$value;
		} else {
		   $tempvalue='"'.addslashes($value).'"';
		}
		$modstring=$modstring.$key.'='.$tempvalue.',';
	}
	}
	
	
	$fieldnames=substr_replace($fieldnames,"",-8);
	$modstring=substr_replace($modstring,"",-1);
	$SQLmod='UPDATE av_players SET '.$modstring.' WHERE id='.$_GET['id'].';';
	$sendit_mod=mysqli_query($db,$SQLmod) or die(mysqli_error($db));
	mysqli_close($db);
	
	if (isset($_GET['did'])) {
		die(header("Location: av_players_viewall.php?did=".$_GET['did']));
	} else {
		die(header("Location: av_players_viewall.php"));
	}
	
} else {
	$SQLdet='SELECT * FROM av_players WHERE id='.$_GET['id'].';';
	//print $SQLdet;
	$sendit_det=mysqli_query($db,$SQLdet) or die(mysqli_error($db));
	$RSdet=mysqli_fetch_object($sendit_det) or die(mysqli_error($db));

	$SQLd='SELECT * FROM av_divisions;';
	$sendit_d=mysqli_query($db,$SQLd) or die(mysqli_error($db));
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>daleclark.net</title>
<link type="text/css" rel="stylesheet" href="adminstyles.css" />
</head>
<body>
<div id="adminwrapper">
<div id="adminlogo"></div>
<?PHP navigation(); ?>
<div id="admincontent">
<h3>Modifythis Player</h3>
<form name="addForm" method="POST" action="av_players_mod.php?id=<?PHP print $_GET['id']; if (isset($_GET['did'])) { print '&did='.$_GET['did'];} ?>">
<p><span class="label">Full Name</span><span class="inputbox"><input name="fullname" type="text" value="<?PHP print $RSdet->fullname; ?>" /></span></p>
<p><span class="label">Division</span><span class="inputbox"><select name="divisionid">
<?PHP
while ($RSd=mysqli_fetch_object($sendit_d)) {
	print '<option value="'.$RSd->id.'"';
	if ($RSdet->divisionid==$RSd->id) {
		print ' selected';
	}
	print '>'.$RSd->divisionname.'</option>';
}
?>
</select></span></p>
<p><span class="label">Rating</span><span class="inputbox"><select name="rating">
<option value="" selected>...select if applicable</option><option value="A"<?PHP if ($RSdet->rating=='A') { print ' selected'; } ?>>A</option><option value="AA"<?PHP if ($RSdet->rating=='AA') { print ' selected'; } ?>>AA</option><option value="AAA"<?PHP if ($RSdet->rating=='AAA') { print ' selected'; } ?>>AAA</option>
</select></span></p>
<p><input type="submit" value="modify" name="submit" /></p></form>
</div>
</body>
</html>
<?PHP
mysqli_close($db);
?>